/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.barco.ledApi;

import com.ideal.log.Log;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.Properties;


/**
 *
 * @author Huyu
 */
public class LedConfig {

    public static String m_BcmcIp = "192.168.1.5";//Bcmc显示墙所在网段
    public static String m_BcmcPort = "80";//Bcmc显示墙端口
    public static int m_LedPortStart = 40001;//led在bcmc映射
    public static int m_LedPortCount = 5;//led数量

    public static int m_ConnectTimeout = 500;//led连接超时时间
    public static int m_ReadTimeout = 2000;//led返回值读取超时时间

    public static String LedKey1 = "resource";//led显示墙返回值关键字
    public static String LedKey2 = "/ol/data/isAlive/";//led显示墙返回值关键字
    public static String LedKey3 = "name";//led显示墙返回值关键字

    public static final String ProPrefix = "http://";
    public static final String Api = "/ol/data/";//获取所有数据接口

    public static final String AliveApi = "/ol/data/isAlive/";//判断led是否存在
    public static final String HomeUrl = "/ol/data/image/projectorConfig/;"
            + "/ol/data/projectorInfo/;"
            + "/ol/data/projectorControl/;"
            + "/ol/data/image/inputConfig/;"
            + "/ol/data/image/pattern/;"
            + "/ol/data/netConfig/";//led服务器home页请求url
    public static final String ProjectUrl1 = "/ol/data/projectorControl/;"
            + "/ol/data/image/projectorConfig/;"
            + "/ol/data/resolutionEmulation/;"
            + "/ol/data/bidData/projector/;"
            + "/ol/data/fmtrControl/";//led服务器ProjectUrl1
    public static final String ProjectUrl2 = "/ol/data/projectorInfo/";//led服务器ProjectUrl2

    public static final String InputUrl1 = "/ol/data/projectorInfo/";
    public static final String InputUrl2 = "/ol/data/image/inputConfig/";
    public static final String InputUrl3 = "/ol/data/opticalCablePower/";
    public static final String InputUrl4 = "/ol/data/image/inputTiming/";
    public static final String InputUrl5 = "/ol/data/ddc/input1/";
    public static final String InputUrl6 = "/ol/data/image/wallConfig/input1/";
    public static final String InputUrl7 = "/ol/data/ddc/input2/";
    public static final String InputUrl8 = "/ol/data/image/wallConfig/input2/";

    public static final String Color_BrightnessUrl = "/ol/data/fmtrControl/;"
            + "/ol/data/projectorControl/;"
            + "/ol/data/brightnessControl/;"
            + "/ol/data/manualModeSettings/;"
            + "/ol/data/nativeModeSettings/;"
            + "/ol/data/brightnessScaling/;"
            + "/ol/data/uniformityCorrection/";

    public static final String RuntimeUrl = "/ol/data/monitoring/runtimes/";

    public static final String SystemHelthUrl1 = "/ol/data/systemHealth/";
    public static final String SystemHelthUrl2 = "/ol/data/monitoring/";
    public static final String SystemHelthUrl3 = "/ol/data/systemHealth/;/ol/data/ledHealth/";

    public static final String HardwareUrl1 = "/ol/data/bidData/projector/";
    public static final String HardwareUrl2 = "/ol/data/bidData/fmtrBoard/";
    public static final String HardwareUrl3 = "/ol/data/bidData/spectrometer/";
    public static final String HardwareUrl4 = "/ol/data/bidData/ledAsm/";
    public static final String HardwareUrl5 = "/ol/data/bidData/frontEndBox/";
    public static final String HardwareUrl6 = "/ol/data/bidData/cpuBoard/";
    public static final String HardwareUrl7 = "/ol/data/bidData/input1/";
    public static final String HardwareUrl8 = "/ol/data/bidData/input2/";
    public static final String HardwareUrl9 = "/ol/data/bidData/coolingBox/";

    public static final String MaintenanceUrl1 = "/ol/data/image/pattern/";
    public static final String MaintenanceUrl2 = "/ol/data/dbControl/";
    public static final String MaintenanceUrl3 = "/ol/data/bidData/ledAsm/";
    public static final String MaintenanceUrl4 = "/ol/data/ledAsmHistory/";
    public static final String MaintenanceUrl5 = "/ol/data/ledAsmHistory/";
    public static final String MaintenanceUrl6 = "/ol/logging/config/api/";

    public static String getALLApi() {
        String AllStr = HomeUrl + ";" + ProjectUrl1 + ";" + ProjectUrl2 + ";" + InputUrl1 + ";"
                + InputUrl2 + ";" + InputUrl3 + ";" + InputUrl4 + ";" + InputUrl5 + ";"
                + InputUrl6 + ";" + InputUrl7 + ";" + InputUrl8 + ";" + Color_BrightnessUrl + ";"
                + RuntimeUrl + ";" + SystemHelthUrl1 + ";" + SystemHelthUrl2 + ";" + SystemHelthUrl3 + ";"
                + HardwareUrl1 + ";" + HardwareUrl2 + ";" + HardwareUrl3 + ";" + HardwareUrl4 + ";"
                + HardwareUrl5 + ";" + HardwareUrl6 + ";" + HardwareUrl7 + ";" + HardwareUrl8 + ";"
                + HardwareUrl9 + ";" + MaintenanceUrl1 + ";" + MaintenanceUrl2 + ";" + MaintenanceUrl3 + ";"
                + MaintenanceUrl4 + ";" + MaintenanceUrl5;//+ ";" + MaintenanceUrl6;
        String[] str = AllStr.split(";");
        String ApiStr = "";
        for (int i = 0; i < str.length; i++) {
            if (!ApiStr.contains(str[i])) {
                if (i == 0) {
                    ApiStr = ApiStr + str[i];
                } else {
                    ApiStr = ApiStr + ";" + str[i];
                }
            }

        }
        System.out.println(AllStr);
        System.out.println(ApiStr);
        return ApiStr;
    }

    public static void init(String dir) {
        String Path = dir + "LedConfig.ini";
        File f = new File(Path);
        if (!f.exists()) {
            Log.logger.info("File not found ,the path is " + Path);
            return;
        }

        InputStream inputStream = null;
        Properties p = new Properties();
        try {
            inputStream = new FileInputStream(f);
            p.load(inputStream);
            String Ip = p.getProperty("BcmcIp");
            String Port = p.getProperty("Port");
            String ConnectTimeout = p.getProperty("ConnectTimeout");
            String ReadTimeout = p.getProperty("ReadTimeout");
            String ledPortStart = p.getProperty("LedPortStart");
            String LedPortCount = p.getProperty("LedPortCount");

            m_BcmcIp = Ip != null ? Ip : m_BcmcIp;
            m_BcmcPort = Port != null ? Port : m_BcmcPort;
            m_LedPortStart = ledPortStart != null ? Integer.valueOf(ledPortStart) : m_LedPortStart;
            m_LedPortCount = LedPortCount != null ? Integer.valueOf(LedPortCount) : m_LedPortCount;
            m_ConnectTimeout = ConnectTimeout != null ? Integer.valueOf(ConnectTimeout) : m_ConnectTimeout;
            m_ReadTimeout = ReadTimeout != null ? Integer.valueOf(ReadTimeout) : m_ReadTimeout;
            

            Log.logger.info("ledConfig attri m_BcmcIp is " + m_BcmcIp);
            Log.logger.info("ledConfig attri m_BcmcPort is " + m_BcmcPort);
            Log.logger.info("ledConfig attri m_LedPortStart is " + m_LedPortStart);
            Log.logger.info("ledConfig attri m_LedPortCount is " + m_LedPortCount);
            Log.logger.info("ledConfig attri m_ConnectTimeout is " + m_ConnectTimeout);
            Log.logger.info("ledConfig attri m_ReadTimeout is " + m_ReadTimeout);
        } catch (Exception e) {

        }
    }

}
